package io.gitee.twoke.generator.engine.impl.generate.parameter;

import io.gitee.twoke.generator.engine.impl.generate.method.GlobalMethodManager;
import io.gitee.twoke.generator.engine.impl.generate.method.GlobalMethodManagerImpl;

public class GlobalMethodParameterLoader implements ParameterLoader {
    public static final String GLOBAL_METHOD_NAME = "g";
    private GlobalMethodManager methodManager;
    private String exposeName;

    public GlobalMethodParameterLoader(String exposeName) {
        this(exposeName, GlobalMethodManagerImpl.newInstance());
    }

    public GlobalMethodParameterLoader( GlobalMethodManager methodManager) {
        this(GLOBAL_METHOD_NAME, methodManager);
    }

    public GlobalMethodParameterLoader(String exposeName, GlobalMethodManager methodManager) {
        this.methodManager = methodManager;
        this.exposeName = exposeName;
    }

    public GlobalMethodManager getMethodManager() {
        return methodManager;
    }

    public GlobalMethodParameterLoader() {
        this(GLOBAL_METHOD_NAME);
    }

    public String getExposeName() {
        return exposeName;
    }

    public void setExposeName(String exposeName) {
        this.exposeName = exposeName;
    }

    @Override
    public void load(ParameterContext context) {
        context.put(exposeName, methodManager.proxy());
    }

    @Override
    public void unload(ParameterContext context) {
        context.remove(exposeName);
    }

}